package team18.yuejian.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import team18.yuejian.Model.MineModel;
import team18.yuejian.Model.RetrofitModel;
import team18.yuejian.R;
import team18.yuejian.RetrofitListener;
import team18.yuejian.bean.UserBean;

public class MineActivity extends BaseActivity implements View.OnClickListener ,RetrofitListener<UserBean> {

    private TextView usernameView;
    private ImageView userpicView;

    private LinearLayout Mine_Order,Mine_Focus,Mine_ShowPic,Mine_User,Mine_logout,showpic,mine;

    private String username,userpic;
    private String PicUrl;

    public int uid;

    SharedPreferences sp;
    SharedPreferences.Editor editor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine);

        InitView();
        InitEvent();
        showUserMessage();
        /*buttonBottom();*/

    }

    public void showUserMessage(){
        uid = getUserId();

        MineModel mineModel = new MineModel();
        mineModel.Mine(uid,this);

    }

    public void InitView(){
        usernameView = findViewById(R.id.Mine_name);
        userpicView =findViewById(R.id.Mine_pic);
        Mine_Order = findViewById(R.id.Mine_Order);
        Mine_Focus = findViewById(R.id.Mine_Focus);
        Mine_ShowPic = findViewById(R.id.Mine_ShowPic);
        Mine_User = findViewById(R.id.Mine_User);
        Mine_logout = findViewById(R.id.Mine_logout);
        showpic = findViewById(R.id.showpic);
        mine = findViewById(R.id.mine);
    }

    public void InitEvent(){

        Mine_Order.setOnClickListener(this);
        Mine_Focus.setOnClickListener(this);
        Mine_ShowPic.setOnClickListener(this);
        Mine_User.setOnClickListener(this);
        Mine_logout.setOnClickListener(this);
        showpic.setOnClickListener(this);

        showpic.setSelected(false);
        mine.setSelected(true);
    }




    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()){
            case R.id.Mine_Order:
                intent = new Intent(MineActivity.this,MineOrderActivity.class);
                intent.putExtra("type",1);
                Toast.makeText(MineActivity.this,"我的订单",Toast.LENGTH_SHORT).show();
                startActivity(intent);
                break;
            case R.id.Mine_Focus:
                intent = new Intent(MineActivity.this,MineListActivity.class);
                intent.putExtra("type",2);
                Toast.makeText(MineActivity.this,"我的关注",Toast.LENGTH_SHORT).show();
                startActivity(intent);
                break;
            case R.id.Mine_ShowPic:
                intent = new Intent(MineActivity.this,MineListActivity.class);
                intent.putExtra("type",3);
                Toast.makeText(MineActivity.this,"我的晒图",Toast.LENGTH_SHORT).show();
                startActivity(intent);
                break;
            case R.id.Mine_User:
                intent = new Intent(MineActivity.this,MineEditActivity.class);
                Toast.makeText(MineActivity.this,"修改个人信息",Toast.LENGTH_SHORT).show();
                startActivity(intent);
                break;
            case R.id.Mine_logout:
                intent = new Intent(MineActivity.this,ShowPicActivity.class);
               /* sp = getSharedPreferences("user",MODE_PRIVATE);
                editor = sp.edit();
                editor.clear();
                editor.commit();*/
                Toast.makeText(MineActivity.this,"注销后返回登录界面",Toast.LENGTH_SHORT).show();
                startActivity(intent);
                break;
            case R.id.showpic:
                intent = new Intent(MineActivity.this,ShowPicActivity.class);
                startActivity(intent);
                break;
        }
    }


    @Override
    public void onSuccess(UserBean userBean, int flag) {
        String baseurl;
        RetrofitModel retrofitModel = new RetrofitModel();
        baseurl = retrofitModel.getPicUrl();
        username = userBean.getUname();
        userpic = baseurl+"/userimage/"+userBean.getUpic();

        usernameView.setText(username);
        Picasso.with(MineActivity.this).load(userpic).into(userpicView);

        Log.d("图片地址",userpic);
    }

    @Override
    public void onFail(String msg) {

    }

    /*public void buttonBottom(){
        LayoutInflater factory = LayoutInflater.from(MineActivity.this);
        View layout = factory.inflate(R.layout.bottom_menu, null);

        LinearLayout showpic = layout.findViewById(R.id.showpic);

        showpic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MineActivity.this,ShowPicActivity.class);
                startActivity(intent);
            }
        });

    }*/


}
